import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { SPetInfo } from "../../../../../Message/Game/SPetInfo";
import { PetUtil } from "../info/PetUtil";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { PetItem } from "../PetItem";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
//class PetRecoverListRenderer
    
    export  class PetRecoverListRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this.init();
            addEventListener(flash.events.MouseEvent.ROLL_OVER, this.onMouseOver);
            addEventListener(flash.events.MouseEvent.ROLL_OUT, this.onMouseOut);
            this.buttonMode = true;
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            this._petInfo = arg1 as SPetInfo;
            if (this._petInfo) 
            {
                this._nameTxt.htmlText = PetUtil.getPetName(this._petInfo);
                this._petItem.dragSource = this._petInfo;
            }
            else 
            {
                this._nameTxt.text = "";
                this._petItem.dragSource = null;
            }
            return;
        }

        /* internal  */init(): void
        {
            this._itemBg = ObjCreate.createBg(0, 0, 38, 38, this, ImagesConst.PackItemBg);
            this._petItem = new PetItem();
            this._petItem.isDropAble = false;
            this._petItem.width = 32;
            this._petItem.height = 32;
            this._petItem.move(3, 3);
            this.addChild(this._petItem);
            this._nameTxt = ObjCreate.createTextField("", 42, 12, 220, 20, this);
            this._nameTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._nameTxt.multiline = true;
            this._nameTxt.mouseEnabled = false;
            this._overSkin = ResouceConst.getScaleBitmap(ImagesConst.Friend_over);
            this._overSkin.width = 110;
            this._overSkin.height = 43;
            this._selectedBg = GlobalClass.getBitmap(ImagesConst.SelectedBg);
            this._selectedBg.width = 110;
            this._selectedBg.height = 43;
            this._selectedItem = GlobalClass.getBitmap(ImagesConst.SelectedItem);
            this._selectedItem.width = 38;
            this._selectedItem.height = 38;
            return;
        }

        public /* override */ set selected(arg1: Boolean)
        {
            if (this._petInfo) 
            {
                super.selected = arg1;
                if (arg1) 
                {
                    if (this._petInfo) 
                    {
                        addChildAt(this._selectedBg, 0);
                        addChildAt(this._selectedItem, 1);
                        this.dispatchEvent(new Object /* flash.events.Event */(flash.events.Event.CHANGE, true));
                    }
                    if (this._itemBg.parent) 
                    {
                        removeChild(this._itemBg);
                    }
                }
                else 
                {
                    if (this._selectedBg.parent) 
                    {
                        removeChild(this._selectedBg);
                    }
                    if (this._selectedItem.parent) 
                    {
                        removeChild(this._selectedItem);
                    }
                    if (this._itemBg.parent == null) 
                    {
                        addChildAt(this._itemBg, 0);
                    }
                }
                if (this._overSkin.parent) 
                {
                    removeChild(this._overSkin);
                }
            }
            return;
        }

        /* internal  */onMouseOver(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._petInfo && !this.selected) 
            {
                addChildAt(this._overSkin, 0);
            }
            return;
        }

        /* internal  */onMouseOut(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (!_selected) 
            {
                if (this._overSkin.parent) 
                {
                    removeChild(this._overSkin);
                }
            }
            return;
        }

        /* internal */ /* var */_itemBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_petItem: PetItem;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_overSkin: ScaleBitmap;

        /* internal */ /* var */_selectedBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_selectedItem: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_petInfo: SPetInfo;
    }
